package org.rendao.service
{
	import com.googlecode.flexxb.FlexXBEngine;
	
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.navigateToURL;
	
	import org.rendao.entity.QuestionCriteria;
	import org.rendao.service.base.GlobalModule;

	public class ReportService
	{
		public static const REPORT_FORMAT_EXCEL:String = "xls";
		public static const REPORT_FORMAT_PDF:String = "pdf";
		
		private static var _instance:ReportService;
		
		public static function get instance():ReportService {
			if (!_instance) {
				_instance=new ReportService(new SingletonForcer());
			}
			return _instance;
		}
		
		public function ReportService(sf:SingletonForcer) {
		}
		
		private static const REPORT_URL:String = "/service/question/report/{format}";
		public function getReport(criteria:QuestionCriteria, format:String):void {
			var url:String = GlobalModule.hostUrl + REPORT_URL.replace("{format}", format);
			url = url + "?uniqueId=" + new Date().time;
			var request:URLRequest = new URLRequest(url);
			request.data = FlexXBEngine.instance.serialize(criteria);
			request.method = URLRequestMethod.POST;
			request.contentType = "text/xml";
			navigateToURL(request, 'quote');
		}
	}
}
class SingletonForcer
{
}